package com.shuhua.taskServer.controller;

import com.shuhua.common.result.Result;
import com.shuhua.pojo.dto.TeamApplyAuditDTO;
import com.shuhua.pojo.dto.TeamApplyDTO;
import com.shuhua.pojo.entity.TeamApply;
import com.shuhua.pojo.vo.TeamApplyVO;
import com.shuhua.taskServer.service.TeamApplyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 班组申请控制器
 */
@RestController
@RequestMapping("/api/team-applies")
@RequiredArgsConstructor
public class TeamApplyController {

    private final TeamApplyService teamApplyService;

    /**
     * 申请加入班组
     * @param teamApplyDTO 班组申请DTO
     * @return 申请结果
     */
    @PostMapping("/apply")
    public Result<TeamApply> applyJoinTeam(@RequestBody @Valid TeamApplyDTO teamApplyDTO) {
        return teamApplyService.applyJoinTeam(teamApplyDTO);
    }

    /**
     * 审核班组申请
     * @param teamApplyAuditDTO 班组申请审核DTO
     * @return 审核结果
     */
    @PostMapping("/audit")
    public Result<TeamApply> auditTeamApply(@RequestBody @Valid TeamApplyAuditDTO teamApplyAuditDTO) {
        return teamApplyService.auditTeamApply(teamApplyAuditDTO);
    }

    /**
     * 获取班组的申请列表（包含申请人详细信息）
     * @param teamId 班组ID
     * @return 申请列表
     */
    @GetMapping("/team/{teamId}")
    public Result<List<TeamApplyVO>> getTeamApplies(@PathVariable Long teamId) {
        return teamApplyService.getTeamApplies(teamId);
    }

    /**
     * 获取工匠的申请列表（包含申请人详细信息）
     * @param craftsmanId 工匠ID
     * @return 申请列表
     */
    @GetMapping("/craftsman/{craftsmanId}")
    public Result<List<TeamApplyVO>> getCraftsmanApplies(@PathVariable Long craftsmanId) {
        return teamApplyService.getCraftsmanApplies(craftsmanId);
    }
} 